@model SelectMenuItemProductSearchModel

@{
    Layout = "_AdminPopupLayout";

    //page title
    ViewBag.PageTitle = T("Admin.ContentManagement.Menus.MenuItems.SelectProduct").Text;
}
@if (ViewBag.RefreshPage == true)
{
    <script>
        try {
            window.opener.document.getElementById('@(Context.Request.Query["entityIdInput"])').value = '@(ViewBag.entityId)';
            window.opener.document.getElementById('@(Context.Request.Query["entityInfoBlock"])').innerHTML = '@ViewBag.entityInfo';
            window.opener.document.getElementById('@(Context.Request.Query["btnId"])').click();
        }
        catch (e){}
        window.close();
    </script>
}
else
{
    <form asp-controller="Menu" asp-action="MenuItemSelectProductPopup"
        asp-route-menuItemId="@Context.Request.Query["menuItemId"]"
        asp-route-entityIdInput="@Context.Request.Query["entityIdInput"]"
        asp-route-btnId="@Context.Request.Query["btnId"]"
        asp-route-entityInfoBlock="@Context.Request.Query["entityInfoBlock"]">

        <div class="content-header clearfix">
            <h1 class="float-left">
                @T("Admin.ContentManagement.Menus.MenuItems.SelectProduct")
            </h1>
            <div class="float-right">
                &nbsp;
            </div>
        </div>

        <section class="content">
            <div class="container-fluid">
                <div class="form-horizontal">
                    <div class="cards-group">
                        <div class="card card-default card-search card-popup">
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-sm-8">
                                        <div class="form-group row">
                                            <div class="col-sm-5">
                                                <nop-label asp-for="SearchKeywords" />
                                            </div>
                                            <div class="col-sm-7">
                                                <nop-editor asp-for="SearchKeywords" />
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <button type="button" id="search-products" class="btn btn-primary btn-search">
                                            <i class="fas fa-magnifying-glass"></i>
                                            @T("Admin.Common.Search")
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="card card-default">
                            <div class="card-body">
                                @await Html.PartialAsync("Table", new DataTablesModel
                                {
                                    Name = "products-grid",
                                    UrlRead = new DataUrl("MenuItemSelectProductPopupList", "Menu", null),
                                    SearchButtonId = "search-products",
                                    Length = Model.PageSize,
                                    LengthMenu = Model.AvailablePageSizes,
                                    Filters = new List<FilterParameter>
                                    {
                                        new FilterParameter(nameof(Model.SearchKeywords))
                                    },
                                    ColumnCollection = new List<ColumnProperty>
                                    {
                                        new ColumnProperty(nameof(SelectMenuItemProductModel.Id))
                                        {
                                            Title = T("Admin.Common.Select").Text,
                                            Render = new RenderCustom("renderColumnSelectProduct"),
                                            ClassName =  NopColumnClassDefaults.Button,
                                            Width = "50",
                                        },
                                        new ColumnProperty(nameof(SelectMenuItemProductModel.Name))
                                        {
                                            Title = T("Admin.ContentManagement.Menus.MenuItems.SelectProduct.Fields.ProductName").Text
                                        },
                                        new ColumnProperty(nameof(SelectMenuItemProductModel.Published))
                                        {
                                            Title = T("Admin.ContentManagement.Menus.MenuItems.SelectProduct.Fields.Published").Text,
                                            Width = "150",
                                            ClassName = NopColumnClassDefaults.CenterAll,
                                            Render = new RenderBoolean()
                                        }
                                    }
                                })
                                <script>
                                    function renderColumnSelectProduct(data, type, row, meta) {
                                        return '<button type="submit" name="@nameof(SelectMenuItemEntityModel.EntityId)" value="' + row.Id + '" class="btn btn-default">@T("Admin.Common.Select")</button>';
                                    }
                                </script>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

    </form>
}